Part Number Hot Search : 
4ALVCH1 2001854 L5972 TC649VUA SM350A 5ZSXE 6034246 S1205
Product Description
Full Text Search
 

To Download AN3322 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  may 2013 docid18304 rev 1 1/38 AN3322 application note watt-hour meter based on th e stm32f101 microcontroller by ludek holoubek introduction this document describes, in detail, the hardware and software implementation of a watt- hour meter using the stm32f101 microcontroller. this cost effective watt-hour meter uses shunt with an operational amplifier as a current sensor, an embedded 12-bit adc for current and voltage measurement, gpio for lcd management, and a lot of other peripherals for communication, tamper detection, keyboar d, and power disconnection. powerful architecture of the stm32? microcontroller allows sampling at 1 msps. the high sampling rate makes it possible to use methods for adc resolution enhancement. main features ? metrological parts ? microcontroller and external op amp only ? compliant with en 50470-1:2006 class b, precision better than 1% ? starting current 20 ma, nominal current 5 a, maximum current 100 a ? reads the voltage and the current signal up to the 21 st harmonic ? shunt as a current sensor. ct and rogowski coil is optional ? additional parts included in reference design ? lcd driven directly by microcontroller ? keyboard driven directly by microcontroller ? an extra external eeprom for user data ? bi-stable relay, ir communication, serial communication ? backup battery, complete power meter power management www.st.com
contents AN3322 2/38 docid18304 rev 1 contents 1 watt-hour meter using th e stm32 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.1 stm32 adc parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.2 requirements for meter in class b . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 definitions of the power meter parameters (according to en 50407-1:2006) . . . . . 7 1.3 stm32 adc dynamic measurement range . . . . . . . . . . . . . . . . . . . . . . . . 8 1.3.1 voltage measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 1.3.2 there are two current ranges in the meter . . . . . . . . . . . . . . . . . . . . . . . 9 1.4 error sources on the stm32 meter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 1.5 linearity of stm32 adc and its inl reduction . . . . . . . . . . . . . . . . . . . . . 10 1.6 thermal noise present on stm32 meter platform . . . . . . . . . . . . . . . . . . 10 1.7 crosstalk between subsequent multiplexed channels . . . . . . . . . . . . . . . .11 1.8 power and energy measurement by stm32 embedded adc . . . . . . . . . 13 1.9 adc enhancement by oversampling technique . . . . . . . . . . . . . . . . . . . . 15 1.10 output values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 some reference values and constants are defined . . . . . . . . . . . . . . . . . . . . . . . . 16 1.10.1 rms voltage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 1.10.2 rms current - high gained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 1.10.3 rms current - low gained . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 1.10.4 power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 1.10.5 energy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 1.10.6 pulse output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 2 computational issues and compensation al gorithms . . . . . . . . . . . . . 22 2.1 non-coherent sampling issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 2.2 timer evaluation for coherent sampling triggering . . . . . . . . . . . . . . . . . . 24 2.3 timer setting constraints for coherent sa mpling triggering . . . . . . . . . . . . 25 2.4 precise timer setting for coherent sampling . . . . . . . . . . . . . . . . . . . . . . . 26 2.5 frequency measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 2.6 filtering of input signal for proper zero crossing detection . . . . . . . . . . . . 29
docid18304 rev 1 3/38 AN3322 contents 2.7 phase shift correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 2.7.1 phase shift measured for the stm32 meter . . . . . . . . . . . . . . . . . . . . . 30 2.7.2 phase shift correction - error evaluation . . . . . . . . . . . . . . . . . . . . . . . . 30 2.7.3 phase shift correction - filter implementation . . . . . . . . . . . . . . . . . . . . . 33 2.8 calibration procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 2.9 reactive and apparent power computation . . . . . . . . . . . . . . . . . . . . . . . 34 2.10 analog part schematic - part 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 2.11 analog part schematic - part 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 3 references . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
list of tables AN3322 4/38 docid18304 rev 1 list of tables table 1. stm32 adc parameter specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 table 2. stm32 adc input characteristics specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 table 3. crosstalk between subsequent multiplexed channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 table 4. precision vs. timer setting. simulated on signal u (t) = sin (2 x pi x 50 x t). . . . . . . . . . . . . 24 table 5. high speed internal (hsi) rc oscilla tor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 6 table 6. error of instant power caused by phase shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 table 7. document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
docid18304 rev 1 5/38 AN3322 list of figures list of figures figure 1. requirements for class b power meter precision, three ranges . . . . . . . . . . . . . . . . . . . . . 7 figure 2. template used to check meter accuracy (up to i max ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 figure 3. typical thermal noise present on stm32 meter platform. histogram shows noise equivalent to white gaussian noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 figure 4. internal and external analog input pin capacitors and resistors . . . . . . . . . . . . . . . . . . . . . 12 figure 5. complete block diagram of the algorithm used in stm32 power meter . . . . . . . . . . . . . . . 13 figure 6. voltage circuitry of stm32 meter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 figure 7. current circuitry of stm32 meter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 figure 8. current circuitry of stm32 meter, op amp satu ration marked by red circle . . . . . . . . . . . . 16 figure 9. voltage circuitry - calibration c u constant computation . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 figure 10. current circuitry - calibration c i constant computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 figure 11. instant power . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 figure 12. parasitic frequency fh in detail . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 figure 13. error of u rms vs. the timer error in timer ticks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 figure 14. error of u rms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 figure 15. finer calculation of zero cro ssing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 figure 16. voltage signal crossing zero voltage line twice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 figure 17. voltage signal used for correct zero crossing af ter proper filtering. . . . . . . . . . . . . . . . . . . 29 figure 18. zero crossing for green - u, blue - ilg, red- ihg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 figure 19. error of instant power for pf = 1 and pf = 0.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 figure 20. error of instant power caused by phase shift for pf = 1. . . . . . . . . . . . . . . . . . . . . . . . . . . 32 figure 21. error of instant power caused by phase shift for pf = 0.5 . . . . . . . . . . . . . . . . . . . . . . . . . 33 figure 22. analog part schematic - part 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 figure 23. analog part schematic - part 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
watt-hour meter using the stm32 AN3322 6/38 docid18304 rev 1 1 watt-hour meter using the stm32 the following sections describe the necessary feasibility study, theory and computation for the stm32 power meter implementation. the system design, stm32 parameter evaluation, adc feature enhancement, and international standards are also covered here. 1.1 stm32 adc parameters the most important part of the power meter and its microcontroller used in metering applications is the embedded adc. its parameters are the key to deciding if the requirements for precision of the implemented meter can be fu lfilled (international standards mentioned in these sections). the first step is to evaluate the parameters given in the adc specifications: for the given stm32 adc, the specifications and tests show: equation 1 integral non-linearity error is . equation 2 the resolution of the 12-bit adc is = 0.02% of the full scale adc range. equation 3 if , then the accuracy = resolution of given adc. equation 4 the accuracy of the 12-bit adc is = 0.02% of the full scale adc range. 1.2 requirements fo r meter in class b the european standard defining the requirements for electricity metering equipment should be the source of constraints and limits for the design presented in this application note. en 50470-1:2006 and en 50470-3:2006 are refer enced in this case. all the computation is directed to the precision of class b. table 1. stm32 adc parameter specifications symbol parameter test conditions typ. max. unit et total unadjusted error f pclk2 = 24 mhz, f adc = 12 mhz, r ain < 10 k ? , v dda = 3 to 3.6 v t a = 25 c measurements made after adc calibration v ref+ = v dda 1.3 2 lsb eo offset error 1 1.5 eg gain error 0.5 1.5 ed differential linearity error 0.7 1 el integral linearity error 0.8 1.5 e inl 12 bit ? 0,8lsb 12 bit ? = 1 2 12 -------- e inl 12 bit ? 1lsb ? --------
docid18304 rev 1 7/38 AN3322 watt-hour meter using the stm32 definitions of the power meter para meters (according to en 50407-1:2006) rms values indicated i - current - the electrical current flowing through the meter. i st - starting current - the lowest value of the current at which the mete r is declared to register active electrical energy at unity power factor. i min - minimum current - the lowest value of the current at which the european standard specifies accuracy requirements. at and above i min , up to i tr , relaxed accura cy requirements apply. i tr - transitional current - the value of the current at, and above which, up to i max , full accuracy requirements of the european standard apply. i ref - reference current - for direct meters, 10 times the transitional current. (this value is the same as the basic current, i b defined in the en 62052-11, chapter 3.5.1.2.) for current transformer operated meters, 20 times the transitional current. (the value is the same as rated current i n .) i max - maximum current - the highest value of current at which the meter purports to meet the accuracy requirements of this europe an standard (en 62052-11, chapter 3.5.2.). i tr - can be chosen (for class b) from the set of values: 0.5, 1, 1.5 and 2 a example 1 example of one setup for a meter i tr - chosen 0.5 a ist = 0.04 i tr = 20 ma i min = 0.5 i tr = 250 ma i max > 50 i tr , i max > 25 a figure 1 shows the prescribed precision in given current intervals. figure 1. requirements for class b power meter precision, three ranges , vw ? , plq  p$p$ qrwghilqhg , plq ? , wu  p$$  , wu ?  , uhi  ? , pd[ $$!  $0
watt-hour meter using the stm32 AN3322 8/38 docid18304 rev 1 figure 2. template used to check meter accuracy (up to i max ) 1.3 stm32 adc dynamic measurement range the precision and resolution of the adc de termines the dynamic range of measured voltage and current. this sect ion analyses whether the given adc is capable of covering, with its precision and resolution, the whol e range for requested maximum current and voltage. the input current and voltage are scaled to the full scale of the stm32 adc: ? by a voltage divider for voltage measurement ? by a shunt and external operational amplifier for a low current measurement ? by a shunt and external operational amplifier for a high current measurement. 1.3.1 voltage measurement one voltage channel, nominal voltage 230 v rms is used u peak-to-peak = 230 x ? ? 2 x 2 x 120% = 780 v (120% means a safety margin) resolution for 780 v: u lsb:peak-to-peak = 780 v x 0.02% = 0.16 v resolution for 230 v: u lsb:rms = 230 v x 0.02% = 0.055 v rms value 0.02% represents resolution and precision of the adc and is defined in section 1.1: stm32 adc parameters . the range where it is necessary to take care of the precision is between 80% to 115% (extended operating range) of the nominal voltage: u max = 230 v rms x 115% = 253 v rms u min = 230 v rms x 80% = 184 v rms for the lowest and highest voltage value th e precision of the voltage measurement is: error of u max = 0.055 v rms / 184 v rms = 0.030% error u min = 0.055 v rms / 253 v rms = 0.022% error values are much lower than prescribed by standards: 1% >> 0.030%.
docid18304 rev 1 9/38 AN3322 watt-hour meter using the stm32 1.3.2 there are two curre nt ranges in the meter low gain range (lg): for 100 a range a resolution and accuracy with the 12-bit adc are: i max = 100 x 2 x 1.414 = 300 a peak-peak resolution in a for maximum value: 300a x 0.02% = 60 ma resolution in a for rms value: 100 a rms x 0.02% = 20 ma rms minimal error of measurement of current about: ? starting current: i st : 20 ma rms / 20 ma rms = 100% (no precision prescribed) ? minimum current: i min : 20 ma rms / 250 ma rms = 8% (1,5% prescribed) ? transition current: i tr : 20 ma rms / 500 ma rms = 4% (1% prescribed) ? reference current: i ref : 20 ma rms / 5 a rms = 0.4% (1% prescribed) ? maximum current: i max : 20 ma rms / 100 a rms = 0.02% (1% prescribed). error values are lower than prescribed standards in case of i ref and i max . lower currents i min and i tr cannot be measured within this lg range. high gain range (hg): for 10 a range a resolution and accuracy with the 12-bit adc are: i max = 10 x 2 x 1.414 = 28 a peak-peak resolution in a for maximum value: 28 a x 0.02% = 5.8 ma resolution in a for rms value: 10 a rms x 0.02% = 2 . 4 ma rms minimal error of measurement of current about: ? starting current: i st : 2.4 ma rms / 20 ma rms = 12% (no precision prescribed) ? minimum current: i min : 2.4 ma rms / 0.5 a rms = 0.48% (1,5% prescribed) ? transition current: i tr : 2.4 ma rms / 1 a rms = 0.24% (1% prescribed) ? reference current: i ref : 2.4 ma rms / 5 a rms = 0.048% (1% prescribed) ? maximum current: i max : 2.4 ma rms / 10 a rms = 0.024% (1% prescribed). error values are lower than prescribed standards in the case of i st , i min , i tr , and i ref . higher current i max cannot be measured within this hg range due to adc saturation. from the analysis performed in this section it can be seen that a system using one range for voltage and two ranges for cu rrent measurement can fulfill re quirements for the prescribed precision of the system.
watt-hour meter using the stm32 AN3322 10/38 docid18304 rev 1 1.4 error sources on the stm32 meter there are a lot of sources of error when measuring current and voltage. they can be compensated in mostly all cases. 1. adc linearity: it limits total accura cy compensated by adc symmetry, see section 1.5 . 2. temperature: external voltage reference keeps adc conversion stable. 3. op amp and adc offsets: they are remo ved by ac coupling, calibration and digital filtering. 4. adc gain: it is compensated by calibration of the meter. 5. thermal noise present on the stm32 meter pcb board: see section 1.6 . 6. crosstalk between subsequent channel measurement: compensation is discussed in section 1.7 . 7. linearity of op amps: it is present, not compensated. selection of a good op amp is made. 8. phase shift between channels; the compensation is shown in section 2.7 . 1.5 linearity of stm32 adc and its inl reduction increasing the adc resolution does not result in higher accuracy since the techniques for obtaining higher resolution can reduce dnl (differential non-linearity) but not inl (integral non-linearity), see section 1.9: adc enhancement by oversampling technique . the linearity can be enhanced (inl reduction) from 0.7 to 0.17 lsb by the application of a simple technique to the hw and sw design. good knowledge of the adc is assumed for this technique, described in a sepa rate document supplied on request. 1.6 thermal noise present on stm32 meter platform the number of effective bits of a given a dc depends on the presence of noise in the system, namely on the pcb and microcontroller itself. if the noise is white gaussian noise (or similar), the number of effective bits can be recovered by oversampling and decimation mentioned in section 1.9 . figure 3 brings a direct noise measurement of the system. the single voltage level was connected to an input of the adc on the stm32 power meter board and a thousand samples were collected. figure 3 shows a histogram of the values taken.
docid18304 rev 1 11/38 AN3322 watt-hour meter using the stm32 figure 3. typical thermal noise present on stm32 meter platform. histogram shows noise equivalent to white gaussian noise measured thermal noise (overall on the board) degrades the adc resolution and accuracy by 2 to 5 lsb. this means that the number of effective bits drops from 12 to less than 10. to recover from this situation it is necessary to use techniques for noeb (number of effective bits) enhancement, see section 1.9 . using oversampling requ ires, in some cases, the addition of the dithering signal. according to the noise level found in this system, it is not necessary to add the dithering signal. it's add ition does not bring any enhancement in the performance. 1.7 crosstalk between subseq uent multiplexed channels when reading more channels subsequently with maximum speed, values sampled from the subsequent channel may be influenced by the reading of the previous channel. this is called crosstalk between subsequent multiplexed channels. it is caused by the balance of external impedance and capacitance of a signal source and an internal impedance and capacitance of the sample and hold circuit in the given adc. the longer the sample and hold phase, the lower the correlation between subsequent samples. the technique to overcome this phenomenon presented in this section is based on reading every channel in the sequence twice and only th e second value is taken as the valid one. the error is reduced from 0.07% of adc full range to less than 0.0001%. the total conversion time is calculated as follows: equation 5 t conv = sampling time + 12.5 cycles example 2 with an adcclk = 14 mhz and a sampling time of 1.5 cycles: t conv_14mhz = 1.5 + 12.5 = 14 cycles = 1 s
watt-hour meter using the stm32 AN3322 12/38 docid18304 rev 1 example 3 with the setting used in this application adcclk = 9 mhz and a sampling time of 1.5 cycles: t conv_9mhz = 1.5 + 12.5 = 14 cycles = 1.56 s t sampling_time = (1.5 cycles / 14 cycles) x 1.56 s = 167 ns figure 4. internal and external analog input pin capacitors and resistors equation 6 r 129 = 820 ? and r 137 = 820 ? (resistors between an output of op amp and an adc input) r ain = r 129 = r 137 = 820 ? r opamp = 80 ? ?? = rc = (r adc + r ain ) + r opam p) c = 1900 ? x 12 pf = 22.8 ns error % = 100 x exp. [-1 x (t sampling_time / ? )] from table 3 it is recommended to use every second value sampled on the same channel. this approach renders an error caused by this phenomenon negligible. table 2. stm32 adc input characteristics specifications symbol parameter conditio ns min. typ. max. unit radc sampling switch resistance 1 k ? cadc internal sample and hold capacitor 12 pf table 3. crosstalk between subsequent multiplexed channels number of the same channel readings [-] t conv [cycle / s] t sampling_time [ns] error [%] 1 1.5 / 1.55 167 0.07 2 3.0 / 3.10 334 0.00 3 4.5 / 4.65 501 0.00 4 6.0 / 6.20 668 0.00 bje 45.'yyy 7 %% "*/y * - ??" 7 7 5 3 "*/ 
$ qbsbtjujd 7 "*/ 7 7 5 3 "%$ 
$ "%$ 
cju dpowfsufs 4bnqmfboeipme"%$ dpowfsufs
docid18304 rev 1 13/38 AN3322 watt-hour meter using the stm32 1.8 power and energy measurem ent by stm32 embedded adc this section gives a complete overview of th e whole hardware and firmware of the stm32 power meter design. figure 5 shows a block diagram of the firmware, figure 6 and figure 7 show the physical realization of the current and voltage path. figure 5. complete block diagram of the algorithm used in stm32 power meter figure 5 shows the algorithm flow measurement. ? a fast measurement of the current and voltage with injected noise from surrounding environment triggered by network synchronized timer ? decimation of measured samples ? rms values computation ? use of a precise rtc clock source for energy computation.
watt-hour meter using the stm32 AN3322 14/38 docid18304 rev 1 figure 6 shows the connectors of the power meter (cir cles with the numbers 1, 2, 3, and 4) and its connection to the network and load on the left side and voltage and current measurement circuit on the right side. voltage ci rcuitry depicted in this image shows that the voltage divider consists of resistors and a capacitor and it is referenced to u m (v mid ) voltage, which is half of +v ref (2.5 v). the voltage divider has a gain of 0.0027. u m (v mid ) voltage is also measured by the system. figure 6. voltage circuitry of stm32 meter 6 7 7 nje       " 7 /7 44 7/-_7 7 44 45. "%$jo 7 nje "%$jo 7pmubhfejwjefs hbjoy 6 fgg 7 67
6 nby 7  6 h nby
6 nby 6 nje  6 h nby 7 6 njo 6 nje 6 h nby 7 7 3&' 7 ".
docid18304 rev 1 15/38 AN3322 watt-hour meter using the stm32 a current circuit is depicted in figure 7 . the circuit consists of two stages: ? the first stage which amplifies 50 times the voltage across the shunt connected to the current terminals (circles with numbers 2 and 3) ? the second stage which amplifies the signal coming from the first stage. the second stage has two paths with different gain: 1 and 10. both the second stage outputs (for gain of 1 and for gain of 10) are connected to the stm32 adc (adc in2 and adc in3). figure 7. current circ uitry of stm32 meter the introduction of two parallel paths within the second stage with the different gain allows the user to measure with higher resolution at the low current part of the measured current range. even with the two range measurements , an adc enhancement must be employed in order to cover both ranges with desired precision. section 1.9 describes, in detail, a technique for adc enhancement. 1.9 adc enhancement by oversampling technique in order to reach the required precision and resolution of the system, it is necessary to maintain the number of effective bits (noeb) higher than that offered by the embedded adc. after the improvement of the linearity and inl reduction in section 1.5 , it is possible to increase the number of effective bits from 10 bits (see section 1.6: thermal noise present on stm32 meter platform ) up to the 14 bits necessary to reach the required precision of the whole system. the theory and implementation of the resolution enhancement by oversampling is described in a separate document supplied on request.
watt-hour meter using the stm32 AN3322 16/38 docid18304 rev 1 1.10 output values this section and its subsections theoretically compute output values as u rms , i rms , p (instant power), e (energy) and pulse output. these values must be calibrated later on by a gain and an offset constant in order to comp ensate an imprecision in the analog circuitry. some reference va lues and constants are defined adc reference circuit tl431 gives a voltage of 2.5 v u adcref = 2.5 v dc offset value u mid is delivered from u adcref : using voltage divider r116, r117, and r120 u mid = u adcref x r116||r117 / (r116||r117 + r120) = 2.5 x 0.498 = 1.245 v one lsb of the 12-bit adc is equal to: lsb 12-bit = 2.5 v / 4096 = 0.00061 v [v / lsb] conversion constant from i to u for r shunt = 400 ? is: shunt 400 = 2500 [1/ ? ] (1 / u out /i in = r x i/i = r shun t = 0.0004) conversion constant from i to u for r shunt = 200 ? is: shunt 200 = 5000 [1/ ? ] (1 / u out /i in = r x i/i = r shunt = 0.0002) figure 8 shows experimental measurements of the maximum output signal from an operational amplifier used in the current analog circuitry. it can be seen that the signal with peak value (amplitude of the sinus signal with dc value in the middle) higher than 1.245 v is clamped due to the limitation given by u mid , u adcref . figure 8. current circuitry of stm32 meter, op amp saturation marked by red circle
docid18304 rev 1 17/38 AN3322 watt-hour meter using the stm32 1.10.1 rms voltage the voltage analog circuitry is described in detail in this section. main phase voltage is reduced by a voltage divider directly connecte d to the phase voltage. the voltage divider consists of a parallel and serial connection of these components: l 1 + r 1 + c 1 ||c 2 + 12 x r 2 and r 14 the output voltage from the voltage divider is given by the voltdivider that is computed from: equation 7 r all = r 1 + 12 x r 2 + r 14 = 100 r + 12 x 47 k ? + 1.5 k ? = 565.6 k ? equation 8 voltage division is: voltdivider = [-] voltdivider constant means that the i nput voltage is divided by number 377. voltage represented in volts is computed by: equation 9 u lsb in lsb - actual output of adc channel u v in volts - output from meter u v = c u x u lsb the calibration constant for the voltage circuitry consists of: equation 10 c u = voltdivider x lsb 12-bit x v_imprecision where lsb 12-bit is defined in section 1.1: stm32 adc parameters , v_imprecision is the imprecision and tolerance of the components used in analog circuitry, mainly resistors and soldering. since we want the smallest value to be 1 v , we must multiply everything by 1.000.000 additionally. this also helps to maintain the preservation of the precision. in order to save the microcontroller computational power and to keep precision as high as possible, it is beneficial to avoid division operation during all the computations during a period and do it as the last step after every period computation. according to section 1.9: adc enhancement by oversampling technique , during oversampling, the sum of 18 samples from adc results as the v sum value representing measured voltage with higher precision. computation of the voltage rms value takes 44 v sum values. they may only be squared, then summed, and finally they can be divide d by common decimation and rms constant. r 14 r all --------- 1,5k ? 565,6k ? ---------------------- - 0,002652 ==
watt-hour meter using the stm32 AN3322 18/38 docid18304 rev 1 a standard computation of the decimation and rms value computation equation 11 v (i) = 1/18 x sum [u (i)] u rms = ?? 1/44 sqrt [v (i)] 2 computation with delayed division saving the computational power and the precision equation 12 v sum = sum [u (i)] u rms = 1/44 x 1/18 x sqrt (sum {sum [u (i)] (y)} 2 ) the final value must be divide d by 28.1424 (or 28142 if the values are in millivolts) or multiplied by 0.035533 (o r 0.000035533 if the va lues are in millivolts). figure 9. voltage circuitry - calibration c u constant computation 1.10.2 rms current - high gained current analog circuitry is described in detail in this section. main phase current is measured as a voltage on small resistance - shunt. the shunt (r142) converting current to the voltage to be measured has a value of: 1. 200 ? 2. 400 ? the voltage from the shunt is amplified by the first stage of the current amplification with a gain of 50. for current that needs further gain, an additional gain of 10 is added. if a path with the additional multiplication 10 is used, all the variables have index hg (high gain). the complete gain is 50 x 10 = 500 times. the value obtained after the amplification must be multiplied by opampgain hg in order to get the original value. equation 13 opampgain hg = 0.002 i a hg = c i hg x i lsb hg where i lsb is the value in lsb from adc and i a is the curren t in amperes. c i hg = shunt 400 x opampgain hg x lsb 12-bit x hg_imprecision [a / lsb] where shunt 400 and lsb 12-bit were defined in section 1.1: stm32 adc parameters . hg_imprecision is the imprecision and tolerance of the components used in the hg path of analog circuitry; mainly resistors and soldering.  'lylghu 9 ! 9 $'& 9 !/ 6% &ruuhfwlrq / 6%! ?9  'hflpdwlrq  506 frpsxwdwl rq  glylvlrq  $0
docid18304 rev 1 19/38 AN3322 watt-hour meter using the stm32 since we want the smallest value to be 1 a , we must multiply ev erything by 1.000.000 additionally. no decimation, shifts or division are performed during computation in order to preserve precision and reduce microcontroller computation. the correct multiplication or division is done at the end of the whole computational chain. the final value must be divide d by 28.1424 (or 28142 if the values are in milliamperes) or multiplied by 0.035533 (o r 0.000035533 if the valu es are in milliamperes). figure 10. current circuitry - calibration c i constant computation 1.10.3 rms current - low gained the basic gain of the current input is 50. there is an additional gain of 1. if the path with the additional multiplication 1 is used, all the variables have index lg (low gain). the complete gain is: equation 14 opampgain lg = 0.02 i a lg = c i lg x i lsb lg [a] = [a/lsb] x [lsb] where i lsb is the value in lsb from adc and i a is the curren t in amperes. equation 15 c i lg = shunt 400 x opampgain lg x lsb 12-bit x lg_imprecision where shunt 400 and lsb 12-bit were defined in section 1.1: stm32 adc parameters . lg_imprecision is the imprecision and tolerance of the components used in the lg path of analog circuitry; mainly resistors and soldering. the final computation is described in section 1.10.4: power , section 1.10.5: energy , and section 1.10.6: pulse output . 1.10.4 power instant power is computed by: equation 16 p = i (t) x u (t) p w = (c i x c u ) x i in x u in p w = c p x i in x u in 6kxq w $! 9 2sdps  9!9  $'&  9!/6 % &ruuhfwlr q /6% !? $ 'hflpdwlr q  506 frpsxwdwlr q  g lylvlrq $0
watt-hour meter using the stm32 AN3322 20/38 docid18304 rev 1 even the c p is theoretically equal to ( c i x c u ); c p is set during the calibration process as a constant between a supplied instant power p theor and the instant power p w measured by the stm32 power meter. equation 17 p theor = c p x p w the difference between c p given by the calibration process and ( c i x c u ) is given by the phase shift that, even when carefully compensate d, does still not have a negligible influence on the computation of the power. the instant power over one period of mains p w can be computed also from the energy e taken over one period of mains equal to 20 ms: equation 18 equation 19 where t s is the sampling period for u (t) and i (t) . ? t is the period of mains equal to 20 ms. in order to reach the desired prec ision in the pulse generation, p w and all the energy values are computed in w. 1.10.5 energy energy is calculated as a product of current i in , voltage u in , time t timer and power calibration constant c p ( t timer - time in seconds). equation 20 e wh = c p x i in x u in x t timer in order to save the microcontroller computational power, the previously computed instant power p w can be used to get energy. equation 21 e wh = p w x t timer equation 22 equation 23 ? e ? ut ?? it ?? ? t s ? ?? t s ? ut ?? it ?? ? ? ? t 44 ------ ? ut ?? it ?? ? ?? ? === p w ? e ? t ------- - 1 ? t ----- ? t 44 ------ ?? ut ?? it ?? ? ? 1 44 ------ ? ut ?? it ?? ? ? == = ? e fragment 1 44 ------ ? ut ?? it ?? ? t s ? ? ? 1 44 ------ ? t s ?? ut ?? i ? t ?? ? 1 44 ------ ? t 44 ------ ? ut ?? it ?? ? ? ? ==== 1 44 ------ ? t 44 ------ ? ut ?? it ?? ? ? ? = ? e fragment 1 44 ------ ? tp ? ? =
docid18304 rev 1 21/38 AN3322 watt-hour meter using the stm32 to keep energy resolution up to 1 mw, we need power to be specified by 25 bits or more. in order to reach desired precision in the pulse generation, e fragment and all the energy values are computed in ws. 1.10.6 pulse output in order to reduce jitter when generating the pu lse output signal, the following algorithm is used: ? the energy is computed once per period of mains (i.e. every 0.02 s) e wh ? the energy computed is divided by 44. e fragmentwh = e wh / 44 ? this fragment is added to the accumulator every time the adc is triggered (44 times per one period of mains) that is equal to 2.2 khz ? whenever the accumulator surpasses a certain level, e thr , impulse threshold, the pulse led is toggled and the e thr is distracted from the accumulator ? in order to reach desired precision in the pulse generation, e thr and all the energy values are computed in ws. the pulse constant (the number of pulses generated per consumed kwh) is set by the manufacturer. example 4 impulse constant k is set by the manufacturer to: k = 3200 impulses / kwh relation between joules and watts per second is the following: w x s = j w x h = 3600 j kw x h = 3.600.000 j 1 kw x h = 3.600.000.000.000 w x s in order to be able to set correctly e thr , it is necessary to know that 1 impulse means: 3200 impl. ...........................1 kwh 1 impl. ........................... x kwh 3200 impulses = 1 kwh = 3.600.000 j the energy of one impulse e impl is: x = e impl = 1 kwh / k [imp / impl/kwh] = 3.600.000.000.000 / k [ws] e impl = 1125 j = 1125 ws e impl = 1.125.000.000 ws because the led is toggled by reaching the e thr value (impulse-threshold), the generation of one complete pulse (risin g and falling edge) requires two events (two times reaching e thr within e impl step). it is necessary to divide the threshold constant for 1impl e impl by two: e thr = e impl / 2 = 1.125.000.000 / 2 = 562.500.000 ws
computational issues and compensation algorithms AN3322 22/38 docid18304 rev 1 2 computational issues and compensation algorithms this section deals with issues that can in fluence measurements and computation and were not mentioned in section 1.4: error sources on the stm32 meter . the topics covered in this section deal with coherent sampling, precise frequency measurement, proper zero crossing detection and phase shift correction. the correct approach used when dealing with this topic leads to the precision improvement and makes it possible to keep precision in the required range. coherent sampling is the sampling of the period ical signal where the number of the samples per period of the signal is still t he same. the sampling time of t he first sample is still in the same time position in relation to the phase of the sampled signal. the timing of the following samples is still the same and constant. in th is case, 44 samples per period of the mains (50 hz, period 20 ms) are always kept. non-coherent sampling is, on the contrary, th e sampling of the periodical signal where the number of the sample per period of the signa l is not the integer number. the sampling does not need to start in the same position in relation to the phase of the sampled signal. the timing of the subsequent samples can vary. for example, 44.76 samples per period of mains are acquired. it means that the sample rate is a bit higher than required in the case of coherent sampling. 2.1 non-coherent sampling issues if non-coherent sampling is present (it means no integer number of samples per period of mains is taken), it is possible to observe an additional disrupting signal in the graph of computed instant power from such sampled current and voltage. the additional disrupting signal consists of two frequencies: a high frequency f h and a low frequency f l . figure 11. instant power (1) 1. y-axis: voltage, x-axis: cyc les of mains/100 (50 hz). when using the non-coherent sampling, the me asured period of the signal is not completely covered and every period and this coverage differs from period to period. the amount of the
docid18304 rev 1 23/38 AN3322 computational issues and compensation algorithms power computed from these samples is not the same for every period of mains. this causes the parasitic signal with the frequency f h . after some time ( tx ) the coverage of the period is the same as it was at the beginning (in relation to the phase of the measured signal). this time tx is the period of the frequency f h . figure 12. parasitic frequency fh in detail (1) 1. y-axis: voltage, x-ax is: cycles of 50 hz. in this example, the sampling of 44 samples per period is synchronized with a frequency of 49.93785 hz. during every period of the mains, the last sample is displaced by time t diff_sample . equation 24 t diff_sample = 1/50hz - 1/49.93785hz = 0.00002489 s in every cycle of the mains, all the samples are shifted by t diff_sample . they again pass their initial position in the time t shift . equation 25 t shift = (1/ 50 hz) / t diff_sample = 803.5 cycles (of 50 hz) since the computed instant active power is a function with double the frequency of the input voltage and current (negative instant voltage and negative instant current again give instant positive power), the t shift should be divided by two: equation 26 1/f h = (803.5 / 2) * 0.020 s = 8.035 s that the specific sample again passes its initial position does not mean that it is exactly in the same position. this happens after even more cycles of mains. this causes the fluctuation of the instant power by a dditional disruption of signal with f l . the period of f l is, in this example, 17,500 cycles of mains that is equal to 350 s (obtained by a simulation). the jitter in instant power brings jitter to the accumulated energy value that brings the jitter to the led pulse output generation. in order to obtain correct instant power, during every period of the mains, or over a short period of time, it is necessary to provide coherent sampling.
computational issues and compensation algorithms AN3322 24/38 docid18304 rev 1 2.2 timer evaluation for co herent sampling triggering in order to introduce coherent sampling into th e system, it must be evaluated, if the timer and its resolution is precise enough to ensure precise outputs (instant power, rms voltage and current). this section evaluates the qua lity of the synchronization with the network which is possible with the given system. it evaluate s errors in respect to the distance from ideal synchronization to the network. sampling frequency for 44 samples per 20 ms (per one cycle of mains 50 hz) results in the adc sample time of 454.5 ? s. the stm32 timer used for synchronization with the network and for triggering of the adc sampling is a 16-bit timer. this timer has a time stamp generation resolution: 27.777 ns when the stm32 is running on 36 mhz. precision of sampling frequency generation one cycle of 50 hz can be divided exactly into 720.000 steps when using the given timer. the timer generates 16363 time stamp events within two subsequent sampling triggers out of 44. the error of the trigger generation for one sample position is: equation 27 1 / 16363 = 0.000061 = 0.0061% ~ 0.01% experimental results in figure 13 show the influence of the sampling instant generation correctness on the instant power error. table 4. precision vs. timer se tting. simulated on signal u (t) = sin (2 x pi x 50 x t) distance from ideal sampling (timer steps) sample time error (%) urms (v) error u rms (%) p at 1 ? (w) error p (%) 1 0.0089 0.707075 0.004 0.499956 0.009 10 0.0889 0.706794 0.044 0.499557 0.089 100 0.8889 0.703984 0.443 0.467189 0.881 500 4.4444 0.692307 2.093 0.479290 4.142 1000 8.8888 0.681974 3.554 0.465089 6.982 1406 12.4965 0.678874 3.993 0.460870 7.826 2812 24.9956 0.701548 0.786 0.492170 1.566 4218 37.4895 0.724468 -2.455 0.524853 -4.971 5625 (1) 1. 5625 = 11250/2 is exactly half of the sampling period, so the error is zero. table 4 was computed for the same setting taking 64 samples per period instead of 44. for 44 samples per second, the errors indicated are even lower, see the text above table 4 . 50.0000 0.707107 0.000 0.500000 0.000
docid18304 rev 1 25/38 AN3322 computational issues and compensation algorithms figure 13. error of u rms vs. the timer error in timer ticks figure 14. error of u rms (1) 1. detail of figure 13 (zoom in x-axis). table 4 shows that the precision of the timer re solution is enough to make coherent sampling in order to reach the requirements fo r precision. there is no need for additional correction or approximation of the samples, un less the future requir ements for the higher accuracy class of the meter ap pear. the system is always ab le to synchronize to the network frequency with the error of the three step s of the timer constants. this leads to the error of u rms three times 0.004% (according to table 4 ) (that means an error u rms value of 0.012%). this is still ten time s lower than other influences to the system that can affect overall precision. 2.3 timer setting constraints fo r coherent sampling triggering the automatic system that is implemented to synchronize sampling with the network (negative feedback introduced in section 2.4 ) sets one parameter. this parameter is the reload constant of the timer for sampling triggeri ng. allowed values of this constant should be limited to an interval avoiding incorrect system behavior in case it is set to a very different value from the ideal one. the limits of the timer reload constant ar e computed from variation of the stm32 microcontroller main system clock and from allowed variation of the network frequency prescribed by international standards. sample time precision (steps of 16-b it timer at the 36 mhz stm32 device) sample time precision (steps of 16-b it timer at the 36 mhz stm32 device)
computational issues and compensation algorithms AN3322 26/38 docid18304 rev 1 to set the correct limits, it is necessary to combine the maximum error of hsi and network frequency variation: max. hsi error = 3% max. 50 hz variation = 2% the max. deviation from correct frequency is 5%. the mains signal is sampled 44 times per per iod of mains, this re sults in the sample frequency f s : equation 28 f s = 50 hz x 44 samples = 2200 hz f s equal to timer constant c timer that is derived from main system clock. c timer = 36.000.000 hz / 2200 hz = 16363 the maximum and minimum values for the timer constant are: c timer-max = c timer x 105% = 17182 c timer-min = c timer x 95% = 15545 the timer constant can be set from one border ( c timer-max or c timer-min ) to the center value ( c timer ) after 818 steps when updating the constant by one every cycle of mains. that is 818 x 0,02 s = 16 seconds (correction is done every second period of the signal, so, in fact, the pll takes 32 seconds to get from total border to center ). this is too long, so it is necessary to implement faster iteration. section 2.4 shows a fast locking algorithm for synchronization with the mains. 2.4 precise timer setting for coherent sampling all the computation (rms current, rms voltag e, instant power) and the conversion of the instant power into energy needs correct timing and the influence of the stm32 main clock must be taken in account. the high speed internal rc osc illator (hsi) inaccuracy (over a lo ng period) is not an issue, since the frequency is measured and updated ev ery period of mains and the timer is set accordingly. table 5. high speed internal (hsi) rc oscillator symbol parameter conditions min. typ. max. unit f hsi frequency 8 mhz acc hsi accuracy of the hsi oscillator user-trimmed with the rcc_cr register 1 % factory calibrated t a = ?40 to 105 c ?2 2.5 % t a = ?10 to 85 c ?1.5 2.2 % t a = 0 to 70 c ?1.3 2 % t a = 25 c ?1.1 1.8 %
docid18304 rev 1 27/38 AN3322 computational issues and compensation algorithms the meter should be able to measure and correct the mains frequency fluctuation of 2%; it means from 49 to 51 hz acco rding to the internat ional standard. the hsi rc oscillator has a frequency fluctuation 3% (even the internal hsi can be calibrated by rtc to accuracy 1%) over the whole temperature range (the value 3% is used for computation as the worst case). if the combination of the maximum ne twork frequency variation and maximum hsi frequency variation is 5%, it means from 47.5 to 52.5 hz. the meter must be able to adapt to this variation and measure correctly in this range of values. all the computation for precise timing is updated on ly when input voltage is higher than 50 v. a possible voltage drop over some periods can bring a frequency detection error. the international standards allow incorrect measurement during the period of the time when voltage is under 80% of its nominal value. the algorithm for the precise timer setting uses the mains zero crossi ng information. in order to keep the whole number of the samples per period of the mains, the positive zero crossing of the mains must still appear in the same position in the sampled data array (for example: if we detect zero crossing at the 4 th sample out of 44, in the next period of mains the zero crossing must appear in the same position, it means the 4 th sample out of 44). the sample triggering timer constant must be upda ted to keep the zero crossing at the same sample index. the timer constant is updated only if the zero crossing is different from the previous one. if the difference is positive, the timer constant is updated by -1, if the difference is negative, the time r constant is updated by +1. this negative feedback locks the sampling frequency to the frequency of mains. the sampling frequency difference represented by one sample (44 samples per period of 50 hz) is 1.16 hz (which is 2%). if the ti mer setting differs from mains by less than 2%, the difference in zero crossing position app ears after many cycles of mains (the lower the difference, the more cycles there are). if we react only by adding or subtracting value 1 from the timer constant only when the difference is one whole sample, the frequency locking lasts for 225 steps (over the whole range - see the beginning of this section). more than 5 s is needed to stabilize the zero crossing sample index value to less than one between directly subsequent periods of mains. furthermor e, after that synchron ization period, if the difference is lower than one whole sample in dex, the update of the timer is done after the difference appears over more periods and reaches one sample index. typically, the lock-in time is about 30 seconds additionally. reduction of the necessary time for zero cr ossing stabilization (synchronizes the sampling with the mains frequency) can be done by introducing a sample index division in order to get finer and faster zero crossing stabilization. using this techniq ue, the lock-in algorithm needs 1-2 seconds to fully synchronize sampling with the network.
computational issues and compensation algorithms AN3322 28/38 docid18304 rev 1 after detection of the zero crossing position i , the finer zero crossing is computed according to figure 15 , equation 29 and equation 30 . figure 15. finer calculation of zero crossing equation 29 d i = b i / (abs. a i + abs. b i ) equation 30 c + d = 1 where a i is the amplitude of the signal prior to a zero crossing, and b i is the amplitude of the signal after the zero crossing. the sub index position d i computed is in the range from 0 to 1. the difference of the two subsequent zero crossings is d i - d i+1 . the value t update that can be added or subtracted from the trigger timer reload constant must be an integer number bigger that one. t he difference can be divided into 20 steps by the rounding of t update = [20 x (d i - d i+1 )]. this leads to a division of the position index of the zero crossing to 20 sub values. the trigger timer reload constant is updated by this difference to stabilize the zero crossing in this finer position. this makes in itial locking faster (by factor 20). as described in section 2.6 , the signal used for zero crossing detection is filtered so that only fundamental frequency is preset. this av oids errors when computing the zero crossing position finer that one sample index. 2.5 frequency measurement the frequency value is derived from the coherent sampling trigger period. the sampling trigger period is meas ured using a precise exte rnal low speed oscilla tor (lse). from that value the frequency is computed. in order to get a higher resolution of the measured frequency value, more values must be accumulated and averaged. the accumulation of ten values brings the resolution that is sufficient and can be displayed. e d fg $0
docid18304 rev 1 29/38 AN3322 computational issues and compensation algorithms 2.6 filtering of input signal for proper zero crossing detection proper detection of the zero crossing is the key parameter in order to measure and compute all the values correctly. possible problems are caused when the voltage channel contains more harmonics and such a signal with these harmonics crosses the zero voltage line more times. figure 16 shows the voltage signal that is cr ossing the zero line twice. the same situation can be caused not only by higher harmonics but also by noise present in all the circuitry. figure 16. voltage signal crossing zero voltage line twice in order to avoid an incorrect zero crossing detec tion, a filter was introdu ced. the filter is the simple moving average. the length of the filt er is 18. since the number of the samples per period of mains is 44, the filter removes all the harmonics starting at 50 hz with growing attenuation. figure 17 shows the signal after the filtering that allows for fa ilure-less zero crossing detection. figure 17. voltage signal used for correct zero crossing after proper filtering
computational issues and compensation algorithms AN3322 30/38 docid18304 rev 1 since the voltage signal with very low amplitude can lead to incorrect zero crossing detection, the zero crossing detection is not performed on the voltage signal with an amplitude lower that 50 v. the measured frequency and locking to the zero crossing is not updated in this case. 2.7 phase shift correction this section describes how to deal with phase shift in the analog circuitry of the stm32 power meter. the evaluation of the error caused by phase shift and the levels of its correction is computed in section 2.7.1 , section 2.7.2 , and section 2.7.3 . 2.7.1 phase shift measured for the stm32 meter the phase shift that needs to be compensated was measured directly in the stm32 meter. these values help to set the limits and resolution of the phase shift compensation method. figure 18. zero crossing for green - u, blue - ilg, red- ihg figure 18 shows that there is a delay between voltage u and currents i lg and i hg . this delay between u and i lg or between u and i hg is in the same range for both ranges and it is 5 - 8 s. this delay is mainly caused by th e capacitance and inductance in the signal path of the input voltage divider (see section 2.10 ). 2.7.2 phase shift correction - error evaluation the phase shift between voltage and current is also caused by non-simultaneous sampling of these values, see section 1.9 .
docid18304 rev 1 31/38 AN3322 computational issues and compensation algorithms the voltage and i l are shifted by two samples: equation 31 t shift_i_l ~ 2 samples ~3 s ~ 0.05 deg. the voltage and i h are shifted by four samples: equation 32 t shift_i_h ~ 4 samples ~ 6 s ~ 0.1 deg. table 6 shows what level of the phase shift correction is necessary to be reached in order to lower the error caused by the phase shift to an acceptable value. it can be seen that we need to correct the phase shift to a value lower than 0.1 deg. this value can be easily reached by the phase shift compensation filter introduced in section 2.7.3 , compensating with the step of 0.013 deg. the value 0.013 deg. allows negligible erro r of the instant power caused by the phase shift to be reached. data from table 6 are depicted in figure 19 , figure 20 , and figure 21 . table 6. error of instant power caused by phase shift sampling time trigger shifted by [deg.] error of instant power [%] for pf = 1 error of inst ant power [%] for pf = 0.5 0.01 0.000002 0.030232 0.02 0.000006 0.060466 0.05 0.000038 0.151200 0.1 0.000152 0.302500 0.2 0.000609 0.605200 0.5 0.003808 1.515300 1 0.015230 3.038100 2 0.060917 6.105700 5 0.380500 15.476300
computational issues and compensation algorithms AN3322 32/38 docid18304 rev 1 figure 19. error of instant power for pf = 1 and pf = 0.5 figure 20. error of instant power caused by phase shift for pf = 1            3kdvhvkliwehwzhhq8dqg,>ghj@ (uururilqvwdqwsrzhu>@ irughj irughj $0 )rusrzhuidfwrudqg>frv ghj @            3kdvhvkliwehwzhhq8dqg,>ghj@ (uururilqvwdqwsrzhu>@ irughj irughj $0
docid18304 rev 1 33/38 AN3322 computational issues and compensation algorithms figure 21. error of instant power caused by phase shift for pf = 0.5 2.7.3 phase shift correctio n - filter implementation the phase shift in the time domain is not as simple as in the frequency domain or in a system where more adc are em ployed for current and voltag e measurements. in this hw implementation we need to use an approach that allows us effectively interpolate values of the voltage so that they are correctly aligned to current. this approach is described in a separate document supplied on request. the phase compensation range that may be reached with this approach is: with the step of 0.73 s (0.013 deg.) maximum positive shift = -6.2 s (0.11 deg.) maximum negative shift = +6.2 s (0.11 deg.) with the step of 0.77 s (0.014 deg.) maximum positive shift = -12.4 s (0.22 deg.) maximum negative shift = +12.4 s(0.22 deg.) when a higher value of the phase shift needs to be compensated, an extension to the method used is introduced. 2.8 calibration procedure calibration (computation of the correction fact or between measured and expected output) is a very important process and its correct performance results in the overall desired precision. even when the power meter measures the cu rrent and voltage with the maximum error 0.5%, we need to perform calibration on an even higher level of accuracy. if this is not done, calibrate the meter with the error of 0.5%, in the worst case (over the whole measured range) the maximum error may be an additional 0.5%, which results in an error of 1% (0.5 + 0.5) in total. this means that the measured value should be used for calibration after its error is the lowest possible . this happens after averaging the value over a longer period )rusrzhuidfwru             3kdvhvkliwehwzhhq8dqg,>ghj@ (uururilqvwdqwsrzhu>@ irughj $0
computational issues and compensation algorithms AN3322 34/38 docid18304 rev 1 of time. calibration is performed, in this case, after the collection of data (rms voltage, rms current, instant active and reactive power) over 64 periods of mains (a bit more than one second or 50 hz). if the error during the calibration process reduces to 0.1%, in the worst case there is an error of 0.6%, (0.1 + 0.5) in total over all the tests. the calibration procedure consists of these steps: 1. connecting the stm32 meter to precise power supply. 2. setting nominal current for lower range (5 a) current and nominal voltage (230 v). 3. after the power supply stabilizes (refer to the vo ltage and curr ent source specifications), wait for an additional two seconds at least (in order to collect enough calibration data). 4. pressing the button (number 4) on the meter keyboard. 5. setting nominal current for higher meter range (40 a) and nominal voltage (230 v). 6. after the power supply stabilizes (refer to the voltage and current source specification), wait for an additional two seconds at least (in order to collect enough calibration data). 7. pressing the button (number 4) on the meter keyboard. 8. after this procedure, all the calibrations are written into eeprom and loaded after every power-up of the power meter. 2.9 reactive and appare nt power computation the reactive power can be computed simply by q = ?? s 2 + p 2 or by using a filtering method. since the first method has its limitations, the filtering approach is in troduced. this approach is described in a separate document supplied on request.
docid18304 rev 1 35/38 AN3322 computational issues and compensation algorithms 2.10 analog part schematic - part 1 figure 22. analog part schematic - part 1 1. the component is optional and the user can fine tune its value according to their requirements. 9 uhi 5 5 9 66 5 & q) 9 plg 9 plg 8 & q) / 9 plg      8& 76,' 5 5 5 59 6. 5 5 5 5 5      8$ 76,' 5 9 66 9 &&      8' 76,' 5 5 5 5 9 66 9 && 5 5 5 966 9 && ,d , ' //  ' //  9 && 9 66 5 5 5 5 5 5 5  & & 9 uhi zh  *1'  z\  / (0,vxssuhvru 5 5 91 91 91     5 9plg 5 5 5 5   - 9 plg 5 5 5 5   - ' //  ' //  9 && 9 66 ,d , 3 3 5 9 plg   - 9 plg 5rjrzvn l & s)  & s)     9 66 '5 '5 '5 '5 '5 '5 '5 '5 '5 '5 '5 '5 9 3 & q) 13  & q) 13  & 966 $0        
computational issues and compensation algorithms AN3322 36/38 docid18304 rev 1 2.11 analog part schematic - part 2 figure 23. analog part schematic - part 2 & q) & q) 5 5 9 66 & q) 9 && 9plg & 5      8% 76,' 5  : 9 uhi 3 3 5 8 7/& 9 66 5 9 && & q) & 9 66 9 && & 9 66 5 $0
docid18304 rev 1 37/38 AN3322 references 3 references improving adc results through oversampling and post-processing of data. (n.d.). retrieved 2009, from actel: www.ac tel.com/documents/improve_adc_wp.pdf. an2668 - application note. 4 revision history table 7. document revision history date revision changes 13-may-2013 1 initial release.
AN3322 38/38 docid18304 rev 1 please read carefully: information in this document is provided solely in connection with st products. stmicroelectronics nv and its subsidiaries (?st ?) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described he rein at any time, without notice. all st products are sold pursuant to st?s terms and conditions of sale. purchasers are solely responsible for the choice, selection and use of the st products and services described herein, and st as sumes no liability whatsoever relating to the choice, selection or use of the st products and services described herein. no license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. i f any part of this document refers to any third party products or services it shall not be deemed a license grant by st for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoev er of such third party products or services or any intellectual property contained therein. unless otherwise set forth in st?s terms and conditions of sale st disclaims any express or implied warranty with respect to the use and/or sale of st products including without limitation implied warranties of merchantability, fitness for a parti cular purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. st products are not authorized for use in weapons. nor are st products designed or authorized for use in: (a) safety critical applications such as life supporting, active implanted devices or systems with product functional safety requirements; (b) aeronautic applications; (c) automotive applications or environments, and/or (d) aerospace applications or environments. where st products are not designed for such use, the purchaser shall use products at purchaser?s sole risk, even if st has been informed in writing of such usage, unless a product is expressly designated by st as being intended for ?automotive, automotive safety or medical? industry domains according to st product design specifications. products formally escc, qml or jan qualified are deemed suitable for use in aerospace by the corresponding governmental agency. resale of st products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by st for the st product or service described herein and shall not create or extend in any manner whatsoev er, any liability of st. st and the st logo are trademarks or registered trademarks of st in various countries. information in this document supersedes and replaces all information previously supplied. the st logo is a registered trademark of stmicroelectronics. all other names are the property of their respective owners. ? 2013 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN3322

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X